package com.e3.basdoc.bank.client;

import java.util.ArrayList;
import java.util.List;

import com.e3.basdoc.bank.model.BankModel;
import com.e3.basdoc.region.model.RegionModel;
import com.e3.template.tgf.TGFSimpleFormPanel;
import com.extjs.gxt.ui.client.widget.form.Field;

public class BankFormPanel extends TGFSimpleFormPanel<BankModel> {

	@Override
	public List<Field<?>> getFormFields() {
		String[] fieldNames = {BankModel.ID,BankModel.CODE,BankModel.NAME,BankModel.SHORT_NAME,BankModel.ADDRESS,BankModel.PARENT_BANK,BankModel.REGION,BankModel.REMARK};
		List<Field<?>> fields = new ArrayList<Field<?>>(fieldNames.length);
		for (String fName : fieldNames) {
			Field<?> field = BankHelper.INSTANCE.createFormField(fName);
			fields.add(field);
		}
		return fields;
	}

	@Override
	public BankModel createModelInstance() {
		return new BankModel();
	}

	@Override
	protected void setModelValue(BankModel model, String name, Object value) {
		if(BankModel.PARENT_BANK.equals(name)){
			model.setParentBank((BankModel)value);
		}
		else if(BankModel.REGION.equals(name)){
			model.setRegionModel((RegionModel)value);
		}
		else{
			super.setModelValue(model, name, value);
		}
	}

	
}
